package com.dc.gameserver.serverCore.service.effective;

import com.google.protobuf.MessageLite;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;

import javax.annotation.PostConstruct;

/**
 * @author 石头哥哥 </br>
 *         dcserver1.3 </br>
 *         Date:13-12-30 </br>
 *         Time:下午5:39 </br>
 *         Package:{@link com.dc.gameserver.serverCore.service.effective}</br>
 *         Comment：
 */
public abstract class abstractEffective implements IEffective {

    /**
     * spring 初始化索引
     */
    @PostConstruct
    public abstract void PostConstruct();


    /**
     * Encoder buffer            </br>
     * 包长度2字节            </br>
     * @param ID  数据包编号
     * @param messageLite 将其转化为byte[]
     * @return
     */
    public ByteBuf wrappedBufferShort(int ID, MessageLite messageLite) {
        ByteBuf buffer= PooledByteBufAllocator.DEFAULT.heapBuffer(0x40);
        buffer.setIndex(0,0x2);//设定writeIndex指针位置
        buffer.writeInt(ID); //编号
        if (messageLite!=null)buffer.writeBytes(messageLite.toByteArray());
        buffer.setShort(0,buffer.writerIndex()- 0x2);
        messageLite=null;
        return buffer;
    }


}
